jQuery(function($) {
				
	/* 激活tooltip提示框 */
	$("[data-toggle='tooltip']").tooltip();
	
 	$(document).on('click', '.toolbar a[data-target]', function(e) {
		e.preventDefault();
		var target = $(this).data('target');
		$('.widget-box.visible').removeClass('visible');//hide others
		$(target).addClass('visible');//show target
 	});

 	//注册时判断用户名是否可用
 	$('#regist-username').bind('focusout',function(){
 		console.log($('#regist-username').val());
 		$.ajax({
 			url: '/admin/sys/user/userAlreadyExists',
 			data: {'username':$('#regist-username').val()},
 			dataType: 'json',
 			async: false,
 			success:function(obj){
 				if(obj.status == 200){
 					gritterSuccess(obj.data);
 				}else
 					gritterError(obj.msg);
 			},
 			error:function(obj){
 				gritterError('请求错误');
 			}
 		});
 	});
 	
 	//切换背景颜色
 	$('#btn-login-dark').on('click', function(e) {
		$('body').attr('class', 'login-layout');
		$('#id-text2').attr('class', 'white');
		$('#id-company-text').attr('class', 'blue');
		
		e.preventDefault();
	});
	$('#btn-login-light').on('click', function(e) {
		$('body').attr('class', 'login-layout light-login');
		$('#id-text2').attr('class', 'grey');
		$('#id-company-text').attr('class', 'blue');
		
		e.preventDefault();
	});
	$('#btn-login-blur').on('click', function(e) {
		$('body').attr('class', 'login-layout blur-login');
		$('#id-text2').attr('class', 'white');
		$('#id-company-text').attr('class', 'light-blue');
		
		e.preventDefault();
	});
 
	//成功的提示框
	function gritterSuccess(text){
		$.gritter.add({
			title: '系统提示',
			text: text,
			time: 2000,
			class_name: 'gritter-success'
		});
	}

	//错误的提示框
	function gritterError(text){
		$.gritter.add({
			title: '系统提示',
			text: text,
			time: 2000,
			class_name: 'gritter-error'
		});
	}
});